package com.huo.base.threadtest;

/**
 * 守护线程
 */
public class DaemonTest {
    public static void main(String[] args) {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("守护线程");
                }

            }
        });
        thread.setDaemon(true);
        thread.start();
        for (int i =0;i<5;i++){
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("主进程i值："+i);
        }
        thread.stop();
        System.out.println("主进程执行完毕");
    }
}
